let data:{}

// let data2:object = 2
let data2:object = {
    age:23
}

// 联合类型
let str:string | number = 'abc'
str = 3


// 交叉类型
type Obj1={username:string} // type可以定义任意数据类型
type Obj2={age:number}
let obj1:Obj1={username:"abc"}
let obj2:Obj2={age:16}

let obj3:Obj1 & Obj2={username:"123",age:123}

// 字面量数据类型:
// 1|2, x
type num=1|2|3
// let n:num = 4
// 示例
type increaseFlag = 0|1
function isStartUp(increase:increaseFlag){
    if(increase){
        console.log('open');
    }else{
        console.log('close');
    }
}
isStartUp(1)
// isStartUp(2)---error


// never
// 使用never 避免出现未来扩展新的类没有对应类型的实现，目的是写出类型绝对安全的代码
type DataFlow = string | number
function aa(dataFlow:DataFlow){
    if(typeof dataFlow === 'string'){
        console.log('字符串类型',dataFlow.length);
    } else if(typeof dataFlow === 'number'){
        console.log('字符串类型',dataFlow.toFixed(2));
    } else{
        let data = dataFlow
    }
}
aa('123')
aa(123)

// undefined
let str2: string | undefined
console.log('str2',str2);

function fn(data?:string){
    data!.toString()
}
fn()


//  null



// any,unknown,undefined 可以接受 undefined
// any,unknown,null 可以接受 null
let data3: any = undefined
let data4: unknown = undefined
let data5: undefined = undefined

let data6: any = null
let data7: unknown = null
let data8: null = null



export {}